package com.yourvote.dao.impl;

import com.yourvote.dao.Dao;
import com.yourvote.dao.RegionDao;
import com.yourvote.model.Region;

import javax.persistence.EntityManager;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: pavlo.fedyna
 * Date: 10/25/12
 * Time: 4:21 PM
 * To change this template use File | Settings | File Templates.
 */
public class RegionDaoImpl extends BaseDaoImpl implements RegionDao{
    @Override
    public EntityManager getEM() {
        return Dao.INSTANCE.getEm();
    }

    @Override
    public List<Region> getAll() {
        return (List<Region>)getAll("select r from Region r");
    }

    @Override
    public void add(Region region) {
        persist(region);
    }

    @Override
    public Region getRegion(int id) {
        return null;
    }

    @Override
    public void remove(Region region) {
        Region region1 = getEM().find(Region.class,region);
        getEM().remove(region1);
    }
}
